/********************************************************
 Name          : sleep_s.h
 Author        : Khachatur Gyozalyan
 Copyright     : Copyright by Antel Systems
 Description   :
 **********************************************************/
#ifndef SLEEP_S_H_
#define SLEEP_S_H_

// Include Files


struct SleepModeReg
{
	unsigned char Sleep_Mode                        : 1;
	unsigned char Wakeup_by_Timer                   : 1;
	unsigned char Wakeup_by_UART_activity           : 1;
	unsigned char Wakeup_by_SLEEP_pin_level_change  : 1;
	unsigned char Wakeup_by_WiFi_interrupt          : 1;
	unsigned char Wakeup_by_UHF_interrupt           : 1;
	unsigned char Wakeup_by_USB_interrupt           : 1;
	unsigned char Wakeup_by_Bluetooth_interrupt     : 1;
	unsigned char SLEEP_pin_active_level            : 1;
	unsigned char Deep_Stop_Mode                    : 1;
	unsigned int  Reserved                          : 22;
};


extern unsigned int   gSleepModeReg;
extern unsigned short gQuietTimeout;
extern unsigned short gWakeupTimeout;


#define SLEEP_MODE_BIT_NUM                              0
#define WAKEUP_BY_TIMER_BIT_NUM                         1
#define WAKEUP_BY_UART_ACTIVITY_BIT_NUM                 2
#define WAKEUP_BY_SLEEP_PIN_LEVEL_CHANGE_BIT_NUM        3
#define WAKEUP_BY_WI_FI_INTERRUPT_BIT_NUM               4
#define WAKEUP_BY_UHF_INTERRUPT_BIT_NUM                 5
#define WAKEUP_BY_USB_INTERRUPT_BIT_NUM                 6
#define WAKEUP_BY_BLUETOOTH_INTERRUPT_BIT_NUM           7
#define SLEEP_PIN_ACTIVE_LEVEL_BIT_NUM                  8
#define DEEP_STOP_MODE_BIT_NUM                          9

/*
#define SLEEP_MODE_BIT                        ((gSleepModeReg >> SLEEP_MODE_BIT_NUM                      ) & 0x01)
#define WAKEUP_BY_TIMER_BIT                   ((gSleepModeReg >> WAKEUP_BY_TIMER_BIT_NUM                 ) & 0x01)
#define WAKEUP_BY_UART_ACTIVITY_BIT           ((gSleepModeReg >> WAKEUP_BY_UART_ACTIVITY_BIT_NUM         ) & 0x01)
#define WAKEUP_BY_SLEEP_PIN_LEVEL_CHANGE_BIT  ((gSleepModeReg >> WAKEUP_BY_SLEEP_PIN_LEVEL_CHANGE_BIT_NUM) & 0x01)
#define WAKEUP_BY_WI_FI_INTERRUPT_BIT         ((gSleepModeReg >> WAKEUP_BY_WI-FI_INTERRUPT_BIT_NUM       ) & 0x01)
#define WAKEUP_BY_UHF_INTERRUPT_BIT           ((gSleepModeReg >> WAKEUP_BY_UHF_INTERRUPT_BIT_NUM         ) & 0x01)
#define WAKEUP_BY_USB_INTERRUPT_BIT           ((gSleepModeReg >> WAKEUP_BY_USB_INTERRUPT_BIT_NUM         ) & 0x01)
#define WAKEUP_BY_BLUETOOTH_INTERRUPT_BIT     ((gSleepModeReg >> WAKEUP_BY_BLUETOOTH_INTERRUPT_BIT_NUM   ) & 0x01)
#define SLEEP_PIN_ACTIVE_LEVEL_BIT            ((gSleepModeReg >> SLEEP_PIN_ACTIVE_LEVEL_BIT_NUM          ) & 0x01)
#define DEEP_STOP_MODE_BIT                    ((gSleepModeReg >> DEEP_STOP_MODE_BIT_NUM                  ) & 0x01)
*/

void sleep_mode_init(void);
void go_static_sleep(void);
void go_deep_sleep(void);
void wake_up(void);
void wake_if(void);
int sleep_task(void);

#endif /* SLEEP_S_H_ */
